package controller;

import model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class StudentController {
    @RequestMapping("/Student/list.do")
    public String list() {
        return "listStudents";//转向到liststudent.html页面，该页面位于WEB-INF的views下
    }

    @RequestMapping(value = "/Student/add.do")
    public String add() {
        return "addStudent";//转向到liststudent.html页面，该页面位于WEB-INF的views下
    }

    @RequestMapping(value = "/Student/login.do", method = RequestMethod.GET)
    public ModelAndView login(String uname, String pswd, Model model) {
        System.out.println("GET:you name is:" + uname + ",your password is" + pswd);
        model.addAttribute("username",uname);
        model.addAttribute("password",pswd);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("uname",uname);
        modelAndView.setViewName("listStudents");
        return modelAndView;
    }

    @RequestMapping(value = "/Student/login1.do", method = RequestMethod.POST)
    public String login1(String uname, String pswd) {
        System.out.println("POST:you name is:" + uname + "your password is" + pswd);
        return "listStudents";
    }
    @RequestMapping("Student/logincheak.do")
    public String logincheak (@RequestParam("xiala") String xiala){
        System.out.println(xiala);
        if(xiala.equals("管理员")){
            return "admin";
        }
        return "user";
    }


    @RequestMapping(value = "/Student/add1.do", method = RequestMethod.POST)
    public String add_post(Student student, Model model) {
        System.out.println("GET:you name is:" + student.getName() + ",your password is" + student.getPwd());
        return "listStudents";
    }
}























